package ferp.android.views.table.animation;

import android.view.View;
import android.view.animation.Animation;
import ferp.android.views.CardView;
import ferp.android.views.table.TableView;
import ferp.core.card.Card;
import ferp.core.game.Game;
import ferp.core.game.Settings;

/**
* User: olegs
* Date: 04/01/2015 22:55
*/
public class AnimationCommitListener extends AnimationListener
{
  public AnimationCommitListener(TableView.Listener listener, TableView table, CardView view, int player, Card card)
  {
    super(table, view);

    this.listener = listener;
    this.player = player;
    this.card = card;
  }

  @Override
  protected void onRealAnimationStart(Animation animation) {view.show(true);}

  @Override
  protected void onRealAnimationEnd(Animation animation)
  {
    Game g = table.game();
    Settings settings = table.settings();

    // show the card in the trick
    table.showTrickCard(player, card);

    view.clearAnimation();

    // hide the card
    view.setVisibility(View.GONE);

    // although current controller is reset in 'advance' method it has to be reset here as well to avoid bad user experience
    // when next card that takes place of the animated one is elevated/shifted and than moved back to player's hand
    table.resetController();

    // redraw the hand
    table.layoutPlayerCards(settings, player);

    // notify the listener about commit animation end
    listener.onCardCommit(card);

    // hide the tutorial mark
    if (g.tutorial() && g.mode().mover(g, settings, g.player.current) == g.human())
      table.hideMark(0);
  }

  private TableView.Listener listener;
  private int player;
  private Card card;
}
